package data_report

import (
	"context"

	"gitee.com/liuxuezhan/ar-platform/rpc-client/analysisClient/rpc"
	"github.com/jinzhu/copier"

	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/svc"
	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type DataStatisticsReportLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

// 渠道报表
func NewDataStatisticsReportLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DataStatisticsReportLogic {
	return &DataStatisticsReportLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *DataStatisticsReportLogic) DataStatisticsReport(req *types.DataStatisticsReportRequest) (resp *types.DataStatisticsReportResponse, err error) {
	resp = &types.DataStatisticsReportResponse{
		RechargeTypeList:   make([]types.RechargeTypeData, 0),
		RechargeStatusList: make([]types.RechargeStatusData, 0),
		WithdrawTypeList:   make([]types.WithdrawTypeData, 0),
		WithdrawStatusList: make([]types.WithdrawStatusData, 0),
	}

	dataStatisticsAnalysisReq := &rpc.SearchArDataStatisticsAnalysisReq{
		StartTime: req.StartTime,
		EndTime:   req.EndTime,
		Domain:    req.Domain,
		AgentId:   req.AgentId,
		Page:      req.Page,
		PageSize:  req.PageSize,
	}
	dataStatisticsAnalysisResp, err := l.svcCtx.Analysis.SearchArDataStatisticsAnalysis(l.ctx, dataStatisticsAnalysisReq)
	if err != nil {
		return nil, err
	}

	copier.Copy(&resp.RechargeTypeList, dataStatisticsAnalysisResp.RechargeTypeList)
	copier.Copy(&resp.RechargeStatusList, dataStatisticsAnalysisResp.RechargeStatusList)
	copier.Copy(&resp.WithdrawTypeList, dataStatisticsAnalysisResp.WithdrawTypeList)
	copier.Copy(&resp.WithdrawStatusList, dataStatisticsAnalysisResp.WithdrawStatusList)
	return
}
